/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.interactions.application;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleData;
import org.eclipse.mosaic.rti.api.Interaction;

import javax.annotation.concurrent.Immutable;
import java.util.List;

import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

/**
 * This extension of {@link Interaction} is used to send simulation step cmd to
 * Other ambassador for co-simulation.
 * The sender usually is SUMO ambassador
 */
@Immutable
public class CoSimulationStep extends Interaction {

    private static final long serialVersionUID = 1L;

    /**
     * String identifying the type of this interaction.
     */
    public final static String TYPE_ID = createTypeIdentifier(CoSimulationStep.class);

    private final List<VehicleData> vehicleUpdates;

    public CoSimulationStep(long time, List<VehicleData> vehicleUpdates) {
        super(time);
        this.vehicleUpdates = vehicleUpdates;
    }

    public List<VehicleData> getVehicleUpdates() {
        return vehicleUpdates;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(5, 71)
                .append(vehicleUpdates)
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }

        CoSimulationStep other = (CoSimulationStep) obj;
        return new EqualsBuilder()
                .append(this.vehicleUpdates, other.vehicleUpdates)
                .isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, SHORT_PREFIX_STYLE)
                .appendSuper(super.toString())
                .append("vehicleUpdates", vehicleUpdates)
                .toString();
    }
}
